<template>
  <div class="history-container">
    <van-cell title="搜索历史">
      <!-- 使用 right-icon 插槽来自定义右侧图标 -->
      <div v-if="delShow">
        <span @click="delAll">全部删除</span>
        <span @click="delShow=!delShow">完成</span>
      </div>
      <van-icon @click="delShow=!delShow" v-else name="delete" class="search=icon"/>
    </van-cell>
    <van-cell v-for="(item, index) in historyVal" :key="index">
      <div @click="$emit('search',item)" slot="title">{{item}}==</div>
      <template #right-icon>
        <van-icon @click="delItem(index)" v-show="delShow" name="close"/>
      </template>
    </van-cell>
    <div style="font-size:12px;color:red" v-if="!historyVal.length">这家伙太懒了，没有留下痕迹。。。。</div>
  </div>
</template>
           
<script>
import { SET_TOKEN } from '@/utils/storage.js'
export default {
  data() {
    return {
      delShow: false
    }
  },
  props: {
    historyVal: {
      type: Array
    }
  },
  methods: {
    delItem(i) {
      this.historyVal.splice(i, 1)
      SET_TOKEN('historyVal', this.historyVal)
    },
    delAll() {
      SET_TOKEN('historyVal', null)
      //this.historyVal=[]
      this.$emit('delAllHis')
    }
  }
}
</script>
<style scoped lang='less'>
.history-container {
}
</style>